<?php

require_once "../../CONFIG/base.php";

function json_encode(array $res, $id=false){
    $str="[";
    if($id){
        $cpt=0;
        foreach($res as $id=>$value){
            $cpt++;
            $str.='"'.$id.'":"'.$value.'"';
            if(sizeof($res)!=$cpt){
                $str.=",";
            }
        }
    }
    else{
        foreach($res as $value){
            $cpt++;
            $str.='"'.$value.'"';
            if(sizeof($res)!=$cpt){
                $str.=",";
            }
        }
    }
    $str.="]";
    return $str;
}

header('Content-type: application/json');

$term='';
if(isset($_GET['term'])){
    $term=noAccents($_GET['term']);
}

$gestionGlossaire=new GestionGlossaire($conBDD);
$resG=$gestionGlossaire->getListeGlossaire(array("titre LIKE '%".$term."%'"));
$res=array();

$gestionRole=new GestionRole($conBDD);
$resR=$gestionRole->getAllTags($term);
foreach($resR as $r){
    $res[$r]=$r;
}

foreach($resG as $g){
    $res[$g->getTitre()]=$g->getTitre();
}
echo json_encode($res);
exit;
?>
